﻿using UnityEngine;
using System.Collections;

public class ResetPlayerPosition : MonoBehaviour {
	public GameObject level, player;
	public GameObject[] starts;
	private int currentStart;

	public void setStart(int number) {
		if(number >= starts.Length)
			throw new PlayerPrefsException("Cannot set start index: " + number + " is out of bounds!");

		currentStart = number;
	}

	public void resetPosition() {
		player.GetComponent<CharacterController>().collider.enabled = false;


		level.transform.rotation = starts[currentStart].transform.rotation;
		transform.position = starts[currentStart].transform.position;
		transform.rotation = starts[currentStart].transform.rotation;


		player.GetComponent<CharacterController>().collider.enabled = true;
	}

	void Start () {
		currentStart = 0;
		setStart(0);
		level = GameObject.Find("Level");
		player = GameObject.FindGameObjectWithTag("Player");
	}
}
